home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
A.C.E. 2
/
ACE CD 2.iso
/
FILES
/
UTILS
/
PROCAL13.DMS
/
PROCAL13.adf
/
Rexx
/
months.rexx
next >
Wrap
OS/2 REXX Batch file
|
1991-12-11
|
6KB
|
155 lines
/* Months S. Dicker 6-Aug-89 */
/* */
/* ARexx program used to enter the 3 character month names into */
/* a selected range of cells. If the selected range contains fewer */
/* than 12 cells, only the required number of months to fill the */
/* range will be written. If more than 12 cells are selected, the */
/* fill operation quits after "Dec" has been written. When the */
/* range encompasses more than one row and more than one column, */
/* the cells in the first row will be filled before the second row */
/* is started. */
signal on error /* Trap host command errors. */
address 'Advantage' /* Send commands to Advantage. */
options results /* Enable return of string results. */
months = 'JanFebMarAprMayJunJulAugSepOctNovDec'
'Current' /* Determine current selected range. */
range = result
colon_posn = pos(":",range) /* Look for colon delimiter in range. */
if colon_posn = 0 then /* If no colon, this is not a range. */
do /* Set the start and end cells to */
start_cell = range /* the selected cell. */
end_cell = range
end
else /* Otherwise, it is a range. */
/* Extract the start/end cells from the specified range. */
do
start_cell = left(range,colon_posn - 1)
end_cell = substr(range,colon_posn + 1)
end
start_column = GetColumn(start_cell) /* Determine range of columns */
end_column = GetColumn(end_cell) /* to be filled. */
start_row = GetRow(start_cell) /* Determine range of rows */
end_row = GetRow(end_cell) /* to be filled. */
month_number = 0 /* Start at "January". */
/* Fill cells with month names, row by row. */
do rownum = start_row to end_row
if month_number > 11 then break /* Quit after "December". */
column = start_column /* Reset column pointer. */
/* Fill columns until we run out of months or reach the end */
/* of the row. */
do until month_number > 11 | c2d(column) > c2d(end_column)
/* Build complete cell name from row and column. */
next_cell = column || rownum
/* Select the cell to be modified. */
'SelectCell'
value(next_cell)
/* Get next month name. */
month_name = substr(months,month_number*3+1,3)
/* Load month name into cell. */
'PutCell'
month_name
/* Advance to the next column and the next month. */
column = NextColumn(column)
month_number = month_number + 1
end
end rownum
/* Reselect the original range of cells. */
'SelectRange'
value(start_cell)
value(end_cell)
exit /* That's all folks! */
/* >>> Host command error handler <<< */
Error:
exit rc /* Just bail out and return error code. */
/* ----------------------------------------------------------------- */
/* Internal Functions (subroutines) */
/* ----------------------------------------------------------------- */
/* == GetRow: Extract the row number from a cell name. == */
GetRow: procedure
arg CellName /* Function expects to be passed a cell name. */
/* Find the first numeric digit in the cell name. */
start_number = verify(CellName,"0123456789","Match")
/* Extract all characters starting at the first digit and continuing */
/* to the end of the cell name. */
rownum = substr(CellName,start_number)
return rownum
/* == GetColumn: Extract the column label from a cell name. == */
GetColumn: procedure
arg CellName /* Function expects to be passed a cell name. */
/* Find the first numeric digit in the cell name. */
start_number = verify(CellName,"0123456789","Match")
/* Extract all characters in the cell name up to the first numeric */
/* character (start of row number). */
column = left(CellName,start_number-1)
return column
/* == NextColumn: Given the current column label, determine the label == */
/* == for the next sequential column. NOTE: This is a == */
/* == recursive function. == */
NextColumn: procedure
arg ThisColumn /* Function expects to be passed a column label. */
/* If the column label is empty (null string), then we must be */
/* starting a new group of column labels (for example, going */
/* from column ZZ to column AAA. Return an "A". */
if length(ThisColumn) = 0 then
new_column = "A"
/* Otherwise, we must advance the last character in the column */
/* name to the next sequential alphabetic character. */
else
do
col_number = , /* Convert last character */
c2d( right(ThisColumn,1) ) /* to decimal value. */
col_number = col_number + 1 /* Increment to next character. */
new_char = d2c(col_number) /* Convert back to a character. */
/* If we've gone past 'Z', find the next column for the column */
/* label minus the last character and then append an "A" to */
/* this label (start of a new label set). */
if new_char > "Z" then
do
temp_column = left( ThisColumn, length(ThisColumn)-1 )
new_column = NextColumn(temp_column) || "A"
end
/* Otherwise, replace the last character of the column label */
/* with the next sequential character. */
else
new_column = overlay(new_char,ThisColumn,length(ThisColumn))
end
return new_column